package com.gzx.plugin.tjzy.modular.founds.mapper;

import com.gzx.plugin.tjzy.modular.founds.bo.GzxFoundsAmountBo;
import com.gzx.plugin.tjzy.modular.founds.entity.GzxFoundsFlowRecord;
import com.gzx.plugin.tjzy.modular.founds.vo.GzxFoundsAvailableVo;
import com.gzx.plugin.tjzy.modular.founds.vo.GzxFoundsFlowVo;
import org.apache.ibatis.annotations.Select;
import vip.xiaonuo.common.mapper.BaseMapperPlus;

import java.util.List;

/**
 * 充值电话短信流水记录 gzx_founds_flow_record
 *
 * @author xbl
 * &#064;date  2025-03-19
 */
public interface GzxFoundsFlowMapper extends BaseMapperPlus<GzxFoundsFlowRecord, GzxFoundsFlowVo> {

    //根据项目代码获取项目的可用余额
    @Select({
            "<script>",
            " select "+
            " sms_amount as foundsAmount, "+
            " sms_freeze_amount foundsFreeze, "+
            " (sms_amount-sms_freeze_amount) as foundsAvailable "+
            " from "+
            " gzx_project "+
            " where project_code = #{projectCode} "+
            " limit 1 "+
            "</script>"
    })
    GzxFoundsAvailableVo getAvaliableByCode(String projectCode);

    //查看某个产品的短信花了多少钱
    @Select({
            "<script>",
            " SELECT trans_type as transType,sum(founds_amount) as foundsAmount FROM `gzx_founds_flow_record` "+
                    " where create_time between #{projectBeginTime} and #{projectEndTime} "+
                    " and project_name = #{projectName} "+
                    " and founds_type = #{foundsType} "+
                    " <if test='transType != -1'> "+
                    "   and trans_type = #{transType} "+
                    " </if>"+
                    " group by trans_type "+
                    "</script>"
    })
    List<GzxFoundsFlowVo> productAmount(GzxFoundsAmountBo foundsAmountBo);
}
